<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        a {
            text-decoration: none;
            color: white;
        }
        
        #img {
            position: relative;
            margin: 10px auto;
            height: 300px;
            width: 300px;
            background-color: pink;
        }
        
        img {
            width: 100%;
            height: 100%;
        }
        
        .go {
            width: 40px;
            height: 40px;
            background-color: RGBA(0, 0, 0, 0.5);
            text-align: center;
            line-height: 40px;
        }
        
        #left,
        #right {
            position: absolute;
            top: 50%;
            margin-top: -20px;
        }
        
        #right {
            right: 0;
        }
    </style>
</head>

<body>
    <div id="img">
        <img :src="imgArr[index]" alt="">

        <div class="go" id="left" @click="prev" v-show="index!=0">
            <a href="javasript:;">
                <</a>

        </div>
        <div class="go" id="right" @click="next" v-show="index<imgArr.length-1">
            <a href="javasript:;">
                ></a>
        </div>


    </div>
    <!-- 导入开发版本的vue.js -->

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var num = 1;
        var changeImg = new Vue({

            el: "#img",
            data: {
                imgArr: ["images/img1.png",
                    "images/img2.png", "images/img3.png"
                ],
                index: 0,
            },
            methods: {

                prev: function() {
                    this.index--
                },
                next: function() {

                    this.index++;
                }
            }
        })
    </script>
</body>

</html>